import * as THREE from 'three'

// import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
import modifyCityMaterial from '../modify/modifyCityMaterial'
import scene from '../scene'
import AlarmSprite from './AlarmSprite'
import FlyLineShader from './FlyLineShader'
import LightRadar from './LightRadar'
import LightWall from './LightWall'
import MeshLine from './MeshLine'

export default function createCity() {
  const gltfLoader = new GLTFLoader()
  gltfLoader.load('./models/nanjing.glb', gltf => {
    gltf.scene.traverse(obj => {
      if (obj.type === 'Mesh') {
        const cityMaterial = new THREE.MeshBasicMaterial({ color: '#0c016f' })

        obj.material = cityMaterial

        modifyCityMaterial(obj)

        if (obj.name === 'Layerbuildings') {
          const meshLine = new MeshLine(obj.geometry)
          const size = obj.scale.x * 1.001
          meshLine.mesh.scale.set(size, size, size)
          scene.add(meshLine.mesh)
        }
      }
    })
    scene.add(gltf.scene)

    // 添加飞线
    // const flyline = new FlyLineShader()
    // scene.add(flyline.mesh)

    // 添加光墙
    // const lightWall = new LightWall()
    // scene.add(lightWall.mesh)

    // 添加光墙
    // const lightRadar = new LightRadar()
    // scene.add(lightRadar.mesh)

    // 增加警告标识
    // const alarmSprite = new AlarmSprite()
    // scene.add(alarmSprite.mesh)

    // alarmSprite.onClick(e => {
    //   console.log('警告', e)
    // })
  })
}
